﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace XYTXL.Web.View.zhcx
{
    public partial class bjxx : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                Bindnj();

            }
        }

        private void Bindnj()
        {
            //this.Panel2.Visible = false;
           // this.Panel3.Visible = false;
            string m_whfs = "班级年级信息统计";

            SqlParameter[] parameters = new SqlParameter[4];
            parameters[0] = new SqlParameter("@_whfs", m_whfs);
            parameters[1] = new SqlParameter("@_xh", "");
            parameters[2] = new SqlParameter("@_dm1", "");
            parameters[3] = new SqlParameter("@_dm2", "");

            DataSet dsmd = XYTXL.API.DbHelperSQL.RunProcedure("pr_xs_sele", parameters, "mytable");
            this.GVxq.DataSource = dsmd;
            this.GVxq.DataBind();

        }

        protected void GVxq_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Panel2.Visible = true;
            Bindxb();
        }

        private void Bindxb()
        {
            string m_nj = this.GVxq.SelectedDataKey.Values["nj"].ToString();
            string m_whfs = "班级年级信息统计--年级";

            SqlParameter[] parameters = new SqlParameter[4];
            parameters[0] = new SqlParameter("@_whfs", m_whfs);
            parameters[1] = new SqlParameter("@_xh", "");
            parameters[2] = new SqlParameter("@_dm1", m_nj);
            parameters[3] = new SqlParameter("@_dm2", "");

            DataSet dsmd = XYTXL.API.DbHelperSQL.RunProcedure("pr_xs_sele", parameters, "mytable");
            this.GVxb.DataSource = dsmd;
            this.GVxb.DataBind();
        }

        protected void GVxb_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Panel3.Visible = true;
            Bindbj();

        }

        private void Bindbj()
        {
            string m_nj = this.GVxb.SelectedDataKey.Values["nj"].ToString();
            string m_xbdm = this.GVxb.SelectedDataKey.Values["xbdm"].ToString();
            string m_whfs = "班级年级信息统计--学院";

            SqlParameter[] parameters = new SqlParameter[4];
            parameters[0] = new SqlParameter("@_whfs", m_whfs);
            parameters[1] = new SqlParameter("@_xh", "");
            parameters[2] = new SqlParameter("@_dm1", m_nj);
            parameters[3] = new SqlParameter("@_dm2", m_xbdm);

            DataSet dsmd = XYTXL.API.DbHelperSQL.RunProcedure("pr_xs_sele", parameters, "mytable");
            this.GVbj.DataSource = dsmd;
            this.GVbj.DataBind();
        }

        protected void GVbh_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bindxs();
        }

        private void Bindxs()
        {
            //this.nj.Visible = false;
            //this.njtitle.Visible = false;
            //this.xb.Visible = false;
            //this.xbtitle.Visible = false;
            
            string m_bh = this.GVbj.SelectedDataKey.Values["bh"].ToString();
            //string m_xbdm = this.GVxb.SelectedDataKey.Values["xbdm"].ToString();
            string m_whfs = "班级年级信息统计--班级";

            SqlParameter[] parameters = new SqlParameter[4];
            parameters[0] = new SqlParameter("@_whfs", m_whfs);
            parameters[1] = new SqlParameter("@_xh", "");
            parameters[2] = new SqlParameter("@_dm1", m_bh);
            parameters[3] = new SqlParameter("@_dm2", "");

            DataSet dsmd = XYTXL.API.DbHelperSQL.RunProcedure("pr_xs_sele", parameters, "mytable");
            this.GVxs.DataSource = dsmd;
            this.GVxs.DataBind();
        }

        protected void dataout_Click(object sender, EventArgs e)
        {
            Response.Buffer = true;
            Response.Charset = "GB2312";
            string OutPutName = DateTime.Now.ToString("yyyyMMdd");
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + OutPutName + ".xls");

            Response.ContentEncoding = System.Text.Encoding.UTF8;
            //设置输出文件类型为excel文件。 
            Response.ContentType = "application/ms-excel";
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            this.GVxs.RenderControl(oHtmlTextWriter);
            Response.Output.Write(oStringWriter.ToString());
            Response.Flush();
            Response.End();
        }

        public override void VerifyRenderingInServerForm(Control control)
        {
            //base.VerifyRenderingInServerForm(control);
        }
        protected void GVkbkmd_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            for (int i = 0; i < e.Row.Cells.Count; i++)
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                    e.Row.Cells[i].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
            }
        }

    }
}